package com.example.springsecuritydemo;

import ch.qos.logback.core.joran.spi.XMLUtil;
import com.alibaba.fastjson.JSONObject;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;

public class QrCodeTest {
    public static void main(String[] args) throws WriterException, IOException {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", "吴承业");
        jsonObject.put("address", "安徽芜湖");
        jsonObject.put("sex", "男");
        Car car = new Car();
        car.setTyres(4);
        car.setColor("red");
        car.setPaizi("现代");
        jsonObject.put("car", car);

        String s = jsonObject.toString();
        System.out.println(s);
        String content = "http://gotime.free.idcfengye.com/alipay.trade.page.pay-JAVA-UTF-8/";

        Map<EncodeHintType, Object> hints = new HashMap<>();
        Object put = hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
        System.out.println("put: "+put);
        Object o = hints.get(EncodeHintType.CHARACTER_SET);
        System.out.println(o);

        BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, 200, 200);
        String filePath = "D://";
        String fileName = "QrCode.jpg";
        Path path = FileSystems.getDefault().getPath(filePath, fileName);
        MatrixToImageWriter.writeToPath(bitMatrix, "jpg", path);
        Object o1=new Object();
        Object o2=new Object();
        System.out.println("o1 "+o1.hashCode());
        System.out.println("o2 "+o2.hashCode());
    }
}

class Car {
    private Integer tyres;
    private String Paizi;
    private String color;

    public Integer getTyres() {
        return tyres;
    }

    void setTyres(Integer tyres) {
        this.tyres = tyres;
    }

    public String getPaizi() {
        return Paizi;
    }

    void setPaizi(String paizi) {
        Paizi = paizi;
    }

    public String getColor() {
        return color;
    }

    void setColor(String color) {
        this.color = color;
    }
}
